package com.woniuxy.web;



import com.woniuxy.pojo.Person2;
import com.woniuxy.pojo.Home;
import com.woniuxy.pojo.Person;
import com.woniuxy.service.impl.Impl;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/aaa99")
public class MaFanServlet {
    @RequestMapping("/bbb")
    public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
        Impl impl = applicationContext.getBean("impl", Impl.class);
        Map one = impl.findOne(1);
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("msg",one.keySet());
        modelAndView.setViewName("zzz");
        return modelAndView;
    }
    @RequestMapping("/asdasdasdsaa")
    public ModelAndView qingqiucanshu(@RequestParam("name") String username, String password){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("username", "传入的名字是："+username);
        modelAndView.addObject("password", "传入的密码是："+password);
        modelAndView.setViewName("ccc");
        return modelAndView;
    }

    @RequestMapping("/ddd")
    public ModelAndView ddd(@RequestParam("ids") List list , @RequestParam Map map){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("ids",list);
        modelAndView.addObject("map",map);
        modelAndView.setViewName("/ccc.jsp");
        return modelAndView;
    }

    @RequestMapping("/eee")
    public ModelAndView eee(Person p){
        System.out.println(1);
        ModelAndView modelAndView = new ModelAndView();
        System.out.println(p);
        modelAndView.addObject("person",p);
        /*modelAndView.setViewName("ccc");*/
        return modelAndView;
    }

    @RequestMapping("/fff")
    public ModelAndView fff(Home h){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("home",h);
        modelAndView.setViewName("ccc");
        return modelAndView;
    }

    @RequestMapping("/ggg")
    public ModelAndView ggg(Person2 p){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("person2",p);
        modelAndView.setViewName("ccc");
        return modelAndView;
    }
    @RequestMapping("/ggg2")
    public ModelAndView ggg2(@RequestParam("createTime") String s){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("sss",s);
        System.out.println(s);
        modelAndView.setViewName("ccc");
        return modelAndView;
    }
    @Test
    public void ceshi(){
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
        Impl impl = applicationContext.getBean("impl", Impl.class);
        Map one = impl.findOne(1);
        System.out.println(one);
    }
}
